package com.yuxi;

/**
 * 线程休眠的例子
 * Created by yuxi on 17/1/27.
 */
public class SleepDemo {
    public static void main(String[] args) {
        MyThread m = new MyThread();
        //加锁之后看如果一个线程进入休眠,是否其他的线程可以拿到这个锁
        new Thread(m).start();
        new Thread(m).start();
        new Thread(m).start();
    }

    static class MyThread implements Runnable {
        public void run() {
            synchronized (this) {
                try {
                    System.out.println(Thread.currentThread().getName()+"当前线程休眠。。。" + System.currentTimeMillis());
                    Thread.sleep(5000);
                    System.out.println(Thread.currentThread().getName()+"当前线程休眠。。。" + System.currentTimeMillis());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
